package p9;

import java.rmi.StubNotFoundException;

/**
 * @author krystal
 * @date 2022/11/12 15:52
 */
class Person{
    public String name;

    public Person(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}

class Student{
    public String name;
    public int score;

    public Student(String name,int score) {
        this.name = name;
        this.score=score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    public boolean equals(Object obj){
        //1.判断obj和当前对象的关系
        if (this == obj){
            return true;
        }
        //2.脱掉obj的外衣
        if(!(obj instanceof Student)){
            return false;
        }
        //3.obj是student类型的对象且和this当前对象不是同一对象
        Student stu=(Student) obj;
        return this.name.equals(stu.name)  &&  this.score==stu.score;
    }
}

public class Demo1 {
    public static void fun(Object o){
        System.out.println(o);
    }

    public static void main(String[] args) {
        fun(new Person("11"));
        fun(new Student("22",98));

    }
}
